@isTest
private class ContractProductSystemControllerTest {
    static testMethod void testMethod1() {
         // 客户
        Account acc1 = TestUtils.createAccount();
       acc1.Name = '总部';

        insert acc1;

         // 客户
        Account acc2 = TestUtils.createAccount();
        acc2.name = '分支机构';
        acc2.ParentId = acc1.Id;
        
        insert acc2;


 
		ProductStructure__c ps2 = new ProductStructure__c();
        ps2.Classify3__c = '试剂';
        insert ps2;
        // 产品
        Product__c p = TestUtils.createProduct();
        p.bggsjhdj__c = 10.0;
        p.zl__c = '12.5ml';
        p.Purpose__c = '试剂报价用';
        p.ProductStructure__c = ps2.Id;
        
        Product__c p2 = TestUtils.createProduct();
        p2.Name = 'aaaa';
        p2.bggsjhdj__c = 10.0;
        p2.zl__c = '100ml';
        p2.Purpose__c = '试剂报价用';
        p2.ProductStructure__c = ps2.Id;
        
        Product__c p3 = TestUtils.createProduct();
        p3.Name = '测试合同产品';
        p3.bggsjhdj__c = 10.0;
        p3.zl__c = '200ml';
        p3.Purpose__c = '试剂报价用';
        p3.ProductStructure__c = ps2.Id;
        insert new Product__c[] {p, p2,p3};


        ///总部合同
        Contract__c c = new Contract__c();
        c.name = '测试合同';
        c.Account__c = acc1.Id;
        c.Corpcode__c = 'MKSY';
        c.Status__c ='已生效';

        c.Year__c = String.valueOf(Date.today().year()) ;
        insert c;
        
        ///合同产品
        ContractProduct__c  cp = new ContractProduct__c();
        cp.Contract__c = c.Id;
        cp.Product__c = p3.Id;
        insert cp;




        ///分支机构合同
        Contract__c c1 = new Contract__c();
        c1.name = '测试合同';
        c1.Account__c = acc2.Id;
        c1.Corpcode__c = 'MKSY';
        c1.Year__c = String.valueOf(Date.today().year());
        insert c1;
        
        ///合同产品
        ContractProduct__c  cp1 = new ContractProduct__c();
        cp1.Contract__c = c1.Id;
        cp1.Product__c = p2.Id;
        insert cp1;


        PageReference page = new PageReference('/apex/ContractProductSystem?conId=' + c1.Id );
        System.Test.setCurrentPage(page);
        ContractProductSystemController cps = new ContractProductSystemController();
        cps.init();
        cps.resJson = cps.cpListJson;
        cps.saveres();


    }
}